package org.bjou

import org.springframework.dao.DataIntegrityViolationException

class UserResumeController {

    static allowedMethods = [save: "POST", update: "POST", delete: "POST"]

    def index() {
        redirect(action: "list", params: params)
    }

    def list() {
        params.max = Math.min(params.max ? params.int('max') : 10, 100)
        [userResumeInstanceList: UserResume.list(params), userResumeInstanceTotal: UserResume.count()]
    }

    def create() {
         def yearList=[]
        for(i in 1970..<2020)  
        {  
           yearList.add(i)
        }
        
        def monthList=[]
        for(i in 1..12)  
        {  
           monthList.add(i)
        }  
        
        [userResumeInstance: new UserResume(params),yearList:yearList,monthList:monthList]
    }

    def save() {
        def userResumeInstance = new UserResume(params)
        if (!userResumeInstance.save(flush: true)) {
            render(view: "create", model: [userResumeInstance: userResumeInstance])
            return
        }

		flash.message = message(code: 'default.created.message', args: [message(code: 'userResume.label', default: 'UserResume'), userResumeInstance.id])
        //redirect(action: "show", id: userResumeInstance.id)
         redirect(controller: "UserBaseinfo", action: "edit", id: userResumeInstance.userBaseinfo.id, fragment:"tabs-3")
    }

    def show() {
        def userResumeInstance = UserResume.get(params.id)
        if (!userResumeInstance) {
			flash.message = message(code: 'default.not.found.message', args: [message(code: 'userResume.label', default: 'UserResume'), params.id])
            redirect(action: "list")
            return
        }

        [userResumeInstance: userResumeInstance]
    }

    def edit() {
         def yearList=[]
        for(i in 1970..<2020)  
        {  
           yearList.add(i)
        }
        
        def monthList=[]
        for(i in 1..12)  
        {  
           monthList.add(i)
        }  
        def userResumeInstance = UserResume.get(params.id)
        if (!userResumeInstance) {
            flash.message = message(code: 'default.not.found.message', args: [message(code: 'userResume.label', default: 'UserResume'), params.id])
            redirect(action: "list")
            return
        }

        [userResumeInstance: userResumeInstance,yearList:yearList,monthList:monthList]
    }

    def update() {
        def userResumeInstance = UserResume.get(params.id)
        if (!userResumeInstance) {
            flash.message = message(code: 'default.not.found.message', args: [message(code: 'userResume.label', default: 'UserResume'), params.id])
            redirect(action: "list")
            return
        }

        if (params.version) {
            def version = params.version.toLong()
            if (userResumeInstance.version > version) {
                userResumeInstance.errors.rejectValue("version", "default.optimistic.locking.failure",
                          [message(code: 'userResume.label', default: 'UserResume')] as Object[],
                          "Another user has updated this UserResume while you were editing")
                render(view: "edit", model: [userResumeInstance: userResumeInstance])
                return
            }
        }

        userResumeInstance.properties = params

        if (!userResumeInstance.save(flush: true)) {
            render(view: "edit", model: [userResumeInstance: userResumeInstance])
            return
        }

		flash.message = message(code: 'default.updated.message', args: [message(code: 'userResume.label', default: 'UserResume'), userResumeInstance.id])
        //redirect(action: "show", id: userResumeInstance.id)
          redirect(controller: "UserBaseinfo", action: "edit", id: userResumeInstance.userBaseinfo.id, fragment:"tabs-3")
    }

    def delete() {
        def userResumeInstance = UserResume.get(params.id)
        //def userBaseinfoId = userResumeInstance.userBaseinfo.id
        //println userBaseinfoId
        if (!userResumeInstance) {
			flash.message = message(code: 'default.not.found.message', args: [message(code: 'userResume.label', default: 'UserResume'), params.id])
            redirect(action: "list")
            return
        }

        try {
            userResumeInstance.delete(flush: true)
			flash.message = message(code: 'default.deleted.message', args: [message(code: 'userResume.label', default: 'UserResume'), params.id])
            redirect(action: "list")
            //  redirect(controller: "UserBaseinfo", action: "edit", id: userBaseinfoId, fragment:"tabs-3")
        }
        catch (DataIntegrityViolationException e) {
			flash.message = message(code: 'default.not.deleted.message', args: [message(code: 'userResume.label', default: 'UserResume'), params.id])
            redirect(action: "show", id: params.id)
        }
    }
}
